package com.gjh.concurrency.filesearch;

import java.io.File;

/**
 * @author guangjh
 * @version 1.0
 * @date 2020/7/19 17:32
 */
public class SerialFileSearch {
    public static void searchFile(File file, String fileName, Result result) {
        File[] contents = file.listFiles();
        if ((contents == null) || (contents.length == 0)) {
            return;
        }
        for (File content : contents) {
            if (content.isDirectory()) {
                searchFile(content, fileName, result);
            } else {
                if (content.getName().equals(fileName)) {
                    result.setPath(content.getAbsolutePath());
                    result.setFound(true);
                    System.out.printf("Serial Search: path: %s%n", result.getPath());
                    return;
                }
            }
            if (result.getFound()) {
                return;
            }
        }
    }
}
